package com.jinlejia.bbs.dialog;

import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import androidx.appcompat.app.AlertDialog;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.jinlejia.bbs.R;


/**
 * 删除（Dialog）
 */

public class CommonDeleteDialog extends AlertDialog implements View.OnClickListener {
    private String mTitle,mContent;
    public CommonDeleteDialog(Context context, String tile, String content) {
        super(context);
        this.mTitle = tile;
        this.mContent = content;
    }
    private TextView cancle,confirm;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Window window = this.getWindow();
        // *** 主要就是在这里实现这种效果的.
        // 设置窗口的内容页面,shrew_exit_dialog.xml文件中定义view内容
        window.setContentView(R.layout.bbs_dialog_delete_common);
        window.setGravity(Gravity.CENTER);
        window.setBackgroundDrawable(new ColorDrawable());
        window.setLayout(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
        //取消
        cancle = window.findViewById(R.id.id_cancel);
        //确定
        TextView confirm = window.findViewById(R.id.id_confirm);

        //title
        TextView title = window.findViewById(R.id.title);
        //content
        TextView content = window.findViewById(R.id.content);

        title.setText( mTitle);
        content.setText( mContent );

        cancle.setOnClickListener(this);
        confirm.setOnClickListener(this);

    }

    @Override
    public void onClick(View v) {
        if (v.getId()==R.id.id_cancel){
            dismiss();
        }else if (v.getId()==R.id.id_confirm){
            dismiss();
            if(null != confirmListener)
                confirmListener.confirm();
        }
    }

    public interface OnConfirmListener {
        public void confirm();
    }

    private OnConfirmListener confirmListener;

    public void setConfirmListener(OnConfirmListener listener) {
        this.confirmListener = listener;
    }
}
